Pagalba:Formules
__TOC__ Syntax Math markup goes inside ... . The has a button for this. Similarly to HTML, in TeX extra spaces and newlines are ignored. The TeX code has to be put literally: MediaWiki templates, predefined templates, and parameters cannot be used within math tags: pairs of double braces are ignored and "#" gives an error message. However, math tags work in the then and else part of #if, etc. See . Rendering The PNG images are black on white (not transparent). These colors, as well as font sizes and types, are independent of browser settings or CSS. Font sizes and types will often deviate from what HTML renders. Vertical alignment with the surrounding text can also be a problem. The of the images is img.tex. It should be pointed out that most of these shortcomings have been addressed by Maynard Handley, but have not been released yet. The alt attribute of the PNG images (the text that is displayed if your browser can't display images; Internet Explorer shows it up in the hover box) is the wikitext that produced them, excluding the and . Apart from function and operator names, as is customary in mathematics for variables, letters are in italics; digits are not. For other text, (like variable labels) to avoid being rendered in italics like variables, use \mbox or \mathrm. For example, \mbox{abc} gives \mbox{abc} . TeX vs HTML Before introducing TeX markup for producing special characters, it should be noted that, as this comparison table shows, sometimes similar results can be achieved in HTML (see ). \frac{p_{1}}{p_{2}} \ = \ \int_{B_{1}}\!\!\!f\ \Bigg / \int_{B_{2}}\!\!\!f \ \ \nsim\ \ \frac{B_{1}}{B_{2}} The use of HTML instead of TeX is still under discussion. The arguments either way can be summarised as follows. Pros of HTML * In-line HTML formulae always align properly with the rest of the HTML text. * The formula's background, font size and face match the rest of HTML contents and the appearance respects CSS and browser settings. * Pages using HTML will load faster. Pros of TeX * TeX is semantically superior to HTML. In TeX, " x" means "mathematical variable x ", whereas in HTML "x" could mean anything. Information has been irrevocably lost. This has multiple benefits: *# TeX can be transformed into HTML, but not vice-versa. This means that on the server side we can always transform a formula, based on its complexity and location within the text, user preferences, type of browser, etc. Therefore, where possible, all the benefits of HTML can be retained, together with the benefits of TeX. It's true that the current situation is not ideal, but that's not a good reason to drop information/contents. It's more a reason to help improve the situation. *# TeX can be converted to MathML for browsers which support it, thus keeping its semantics and allowing it to be rendered as a vector. * TeX has been specifically designed for typesetting formulae, so input is easier and more natural, and output is more aesthetically pleasing. * When writing in TeX, editors need not worry about browser support, since it is rendered into an image by the server. HTML formulae, on the other hand, can end up being rendered inconsistent of editor's intentions (or not at all), by some browsers or older versions of a browser. Functions, symbols, special characters Subscripts, superscripts, integrals Fractions, matrices, multilines Feature Syntax How it looks rendered Fractions \frac{2}{4}=0.5 \frac{2}{4}=0.5 Small Fractions \tfrac{2}{4} = 0.5 \tfrac{2}{4} = 0.5 Large (normal) Fractions \dfrac{2}{4} = 0.5 \dfrac{2}{4} = 0.5 Large (nestled) Fractions \cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} = a \cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} = a Binomial coefficients \binom{n}{k} \binom{n}{k} Small Binomial coefficients \tbinom{n}{k} \tbinom{n}{k} Large (normal) Binomial coefficients \dbinom{n}{k} \dbinom{n}{k} Matrices \begin{matrix} x & y \\ z & v \end{matrix} \begin{matrix} x & y \\ z & v \end{matrix} \begin{vmatrix} x & y \\ z & v \end{vmatrix} \begin{vmatrix} x & y \\ z & v \end{vmatrix} \begin{Vmatrix} x & y \\ z & v \end{Vmatrix} \begin{Vmatrix} x & y \\ z & v \end{Vmatrix} \begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0 \end{bmatrix} \begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix} \begin{Bmatrix} x & y \\ z & v \end{Bmatrix} \begin{Bmatrix} x & y \\ z & v \end{Bmatrix} \begin{pmatrix} x & y \\ z & v \end{pmatrix} \begin{pmatrix} x & y \\ z & v \end{pmatrix} \bigl( \begin{smallmatrix} a&b\\ c&d \end{smallmatrix} \bigr) \bigl( \begin{smallmatrix} a&b\\ c&d \end{smallmatrix} \bigr) Case distinctions f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases} f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases} Multiline equations \begin{align} f(x) & = (a+b)^2 \\ & = a^2+2ab+b^2 \\ \end{align} * * Multiline equations (must define number of colums used ({lcr}) (should not be used unless needed) \begin{array}{lcl} z & = & a \\ f(x,y,z) & = & x + y + z \end{array} \begin{array}{lcl} z & = & a \\ f(x,y,z) & = & x + y + z \end{array} Multiline equations (more) \begin{array}{lcr} z & = & a \\ f(x,y,z) & = & x + y + z \end{array} \begin{array}{lcr} z & = & a \\ f(x,y,z) & = & x + y + z \end{array} Breaking up a long expression so that it wraps when necessary f(x) \,\! = \sum_{n=0}^\infty a_n x^n = a_0+a_1x+a_2x^2+\cdots f(x) \,\! = \sum_{n=0}^\infty a_n x^n = a_0 +a_1x+a_2x^2+\cdots Simultaneous equations \begin{cases} 3x + 5y + z \\ 7x - 2y + 4z \\ -6x + 3y + 2z \end{cases} \begin{cases} 3x + 5y + z \\ 7x - 2y + 4z \\ -6x + 3y + 2z \end{cases} Alphabets and typefaces Feature Syntax How it looks rendered non-italicised characters \mbox{abc} \mbox{abc} \mbox{abc} \,\! mixed italics (bad) \mbox{if} n \mbox{is even} \mbox{if} n \mbox{is even} \mbox{if} n \mbox{is even} \,\! mixed italics (good) \mbox{if }n\mbox{ is even} \mbox{if }n\mbox{ is even} \mbox{if }n\mbox{ is even} \,\! mixed italics (more legible: ~ is a non-breaking space, while "\ " forces a space) \mbox{if}~n\ \mbox{is even} \mbox{if}~n\ \mbox{is even} \mbox{if}~n\ \mbox{is even} \,\! Parenthesizing big expressions, brackets, bars Feature Syntax How it looks rendered Bad ( \frac{1}{2} ) ( \frac{1}{2} ) Good \left ( \frac{1}{2} \right ) \left ( \frac{1}{2} \right ) You can use various delimiters with \left and \right: Feature Syntax How it looks rendered Parentheses \left ( \frac{a}{b} \right ) \left ( \frac{a}{b} \right ) Brackets \left [ \frac{a}{b} \right ] \quad \left \lbrack \frac{a}{b} \right \rbrack \left [ \frac{a}{b} \right ] \quad \left \lbrack \frac{a}{b} \right \rbrack Braces \left \{ \frac{a}{b} \right \} \quad \left \lbrace \frac{a}{b} \right \rbrace \left \{ \frac{a}{b} \right \} \quad \left \lbrace \frac{a}{b} \right \rbrace Angle brackets \left \langle \frac{a}{b} \right \rangle \left \langle \frac{a}{b} \right \rangle Bars and double bars \left | \frac{a}{b} \right \vert \left \Vert \frac{c}{d} \right \| \left | \frac{a}{b} \right \vert \left \Vert \frac{c}{d} \right \| Floor and ceiling functions: \left \lfloor \frac{a}{b} \right \rfloor \left \lceil \frac{c}{d} \right \rceil \left \lfloor \frac{a}{b} \right \rfloor \left \lceil \frac{c}{d} \right \rceil Slashes and backslashes \left / \frac{a}{b} \right \backslash \left / \frac{a}{b} \right \backslash Up, down and up-down arrows \left \uparrow \frac{a}{b} \right \downarrow \quad \left \Uparrow \frac{a}{b} \right \Downarrow \quad \left \updownarrow \frac{a}{b} \right \Updownarrow \left \uparrow \frac{a}{b} \right \downarrow \quad \left \Uparrow \frac{a}{b} \right \Downarrow \quad \left \updownarrow \frac{a}{b} \right \Updownarrow Delimiters can be mixed, as long as \left and \right match \left [ 0,1 \right ) \left \langle \psi \right | \left [ 0,1 \right ) \left \langle \psi \right | Use \left. and \right. if you don't want a delimiter to appear: \left . \frac{A}{B} \right \} \to X \left . \frac{A}{B} \right \} \to X Size of the delimiters \big( \Big( \bigg( \Bigg( ... \Bigg] \bigg] \Big] \big] \big( \Big( \bigg( \Bigg( ... \Bigg] \bigg] \Big] \big] \big\{ \Big\{ \bigg\{ \Bigg\{ ... \Bigg\rangle \bigg\rangle \Big\rangle \big\rangle \big\{ \Big\{ \bigg\{ \Bigg\{ ... \Bigg\rangle \bigg\rangle \Big\rangle \big\rangle \big\| \Big\| \bigg\| \Bigg\| ... \Bigg| \bigg| \Big| \big| \big\| \Big\| \bigg\| \Bigg\| ... \Bigg| \bigg| \Big| \big| \big\lfloor \Big\lfloor \bigg\lfloor \Bigg\lfloor ... \Bigg\rceil \bigg\rceil \Big\rceil \big\rceil \big\lfloor \Big\lfloor \bigg\lfloor \Bigg\lfloor ... \Bigg\rceil \bigg\rceil \Big\rceil \big\rceil \big\uparrow \Big\uparrow \bigg\uparrow \Bigg\uparrow ... \Bigg\Downarrow \bigg\Downarrow \Big\Downarrow \big\Downarrow \big\uparrow \Big\uparrow \bigg\uparrow \Bigg\uparrow ... \Bigg\Downarrow \bigg\Downarrow \Big\Downarrow \big\Downarrow \big\updownarrow \Big\updownarrow \bigg\updownarrow \Bigg\updownarrow ... \Bigg\Updownarrow \bigg\Updownarrow \Big\Updownarrow \big\Updownarrow \big\updownarrow \Big\updownarrow \bigg\updownarrow \Bigg\updownarrow ... \Bigg\Updownarrow \bigg\Updownarrow \Big\Updownarrow \big\Updownarrow \big / \Big / \bigg / \Bigg / ... \Bigg\backslash \bigg\backslash \Big\backslash \big\backslash \big / \Big / \bigg / \Bigg / ... \Bigg\backslash \bigg\backslash \Big\backslash \big\backslash Spacing Note that TeX handles most spacing automatically, but you may sometimes want manual control. Feature Syntax How it looks rendered double quad space a \qquad b a \qquad b quad space a \quad b a \quad b text space a\ b a\ b text space without PNG conversion a \mbox{ } b a \mbox{ } b large space a\;b a\;b medium space a\>b supported small space a\,b a\,b no space ab ab\, small negative space a\!b a\!b Align with normal text flow Due to the default css img.tex { vertical-align: middle; } an inline expression like \int_{-N}^{N} e^x\, dx = 2 \sinh N should look good. If you need to align it otherwise, use ... and play with the vertical-align argument until you get it right; however, how it looks may depend on the browser and the browser settings. Also note that if you rely on this workaround, if/when the rendering on the server gets fixed in future releases, as a result of this extra manual offset your formulae will suddenly be aligned incorrectly. So use it sparingly, if at all. Forced PNG rendering To force the formula to render as PNG, add \, (small space) at the end of the formula (where it is not rendered). This will force PNG if the user is in "HTML if simple" mode, but not for "HTML if possible" mode (math rendering settings in ). You can also use \,\! (small space and negative space, which cancel out) anywhere inside the math tags. This does force PNG even in "HTML if possible" mode, unlike \,. This could be useful to keep the rendering of formulae in a proof consistent, for example, or to fix formulae that render incorrectly in HTML (at one time, a^{2+2} rendered with an extra underscore), or to demonstrate how something is rendered when it would normally show up as HTML (as in the examples above). For instance: Syntax How it looks rendered a^{c+2} a^{c+2} a^{c+2} \, a^{c+2} \, a^{\,\!c+2} a^{\,\!c+2} a^{b^{c+2}} a^{b^{c+2}} (WRONG with option "HTML if possible or else PNG"!) a^{b^{c+2}} \, a^{b^{c+2}} \, (WRONG with option "HTML if possible or else PNG"!) a^{b^{c+2}}\approx 5 a^{b^{c+2}}\approx 5 (due to " \approx " correctly displayed, no code "\,\!" needed) a^{b^{\,\!c+2}} a^{b^{\,\!c+2}} \int_{-N}^{N} e^x\, dx \int_{-N}^{N} e^x\, dx This has been tested with most of the formulae on this page, and seems to work perfectly. You might want to include a comment in the HTML so people don't "correct" the formula by removing it: :'' Examples Quadratic Polynomial ax^2 + bx + c = 0 ax^2 + bx + c = 0 Quadratic Polynomial (Force PNG Rendering) ax^2 + bx + c = 0\,\! ax^2 + bx + c = 0\,\! Quadratic Formula x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} Tall Parentheses and Fractions 2 = \left( \frac{\left(3-x\right) \times 2}{3-x} \right) 2 = \left( \frac{\left(3-x\right) \times 2}{3-x} \right) S_{new} = S_{old} + \frac{ \left( 5-T \right) ^2} {2} S_{new} = S_{old} + \frac{ \left( 5-T \right) ^2} {2} Integrals \int_a^x \int_a^s f(y)\,dy\,ds = \int_a^x f(y)(x-y)\,dy \int_a^x \int_a^s f(y)\,dy\,ds = \int_a^x f(y)(x-y)\,dy Summation \sum_{m=1}^\infty\sum_{n=1}^\infty\frac{m^2\,n}{3^m\left(m\,3^n+n\,3^m\right)} \sum_{m=1}^\infty\sum_{n=1}^\infty\frac{m^2\,n} {3^m\left(m\,3^n+n\,3^m\right)} Differential Equation u + p(x)u' + q(x)u=f(x),\quad x>a u'' + p(x)u' + q(x)u=f(x),\quad x>a Complex numbers |\bar{z}| = |z|, |(\bar{z})^n| = |z|^n, \arg(z^n) = n \arg(z) |\bar{z}| = |z|, |(\bar{z})^n| = |z|^n, \arg(z^n) = n \arg(z) Limits \lim_{z\rightarrow z_0} f(z)=f(z_0) \lim_{z\rightarrow z_0} f(z)=f(z_0) Integral Equation \phi_n(\kappa) = \frac{1}{4\pi^2\kappa^2} \int_0^\infty \frac{\sin(\kappa R)}{\kappa R} \frac{\partial}{\partial R} \leftD_n(R)}{\partial R}\right\,dR \phi_n(\kappa) = \frac{1}{4\pi^2\kappa^2} \int_0^\infty \frac{\sin(\kappa R)}{\kappa R} \frac{\partial}{\partial R} \leftD_n(R)}{\partial R}\right\,dR Example \phi_n(\kappa) = 0.033C_n^2\kappa^{-11/3},\quad \frac{1}{L_0}\ll\kappa\ll\frac{1}{l_0} \phi_n(\kappa) = 0.033C_n^2\kappa^{-11/3},\quad \frac{1}{L_0}\ll\kappa\ll\frac{1}{l_0} Continuation and cases f(x) = \begin{cases}1 & -1 \le x < 0 \\ \frac{1}{2} & x = 0 \\ 1 - x^2 & 0 < x \le 1\end{cases} f(x) = \begin{cases} 1 & -1 \le x < 0 \\ \frac{1}{2} & x = 0 \\ 1 - x^2 & 0 < x\le 1 \end{cases} Prefixed subscript {}_pF_q(a_1,\dots,a_p;c_1,\dots,c_q;z) = \sum_{n=0}^\infty \frac{(a_1)_n\cdot\cdot\cdot(a_p)_n}{(c_1)_n\cdot\cdot\cdot(c_q)_n}\frac{z^n}{n!} {}_pF_q(a_1,\dots,a_p;c_1,\dots,c_q;z) = \sum_{n=0}^\infty \frac{(a_1)_n\cdot\cdot\cdot(a_p)_n}{(c_1)_n\cdot\cdot\cdot(c_q)_n} \frac{z^n}{n!}